package com.jyw.framework.security.wechat;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

/**
 * @author 沈峻
 * @ClassName 微信登录 AuthenticationToken，模仿 UsernamePasswordAuthenticationToken 实现
 * @Description TODO
 * @Date 2023/9/5 14:45
 **/
public class WechatAuthenticationToken extends AbstractAuthenticationToken {

    /**
     * 在 UsernamePasswordAuthenticationToken 中该字段代表登录的用户名，
     * 在这里代表手机号
     */
    private final Object principal;

    /**
     * 构建一个没有鉴权的 SmsCodeAuthenticationToken
     */
    public WechatAuthenticationToken(Object principal) {
        super(null);
        this.principal = principal;
        setAuthenticated(false);
    }

    /**
     * 构建拥有鉴权的WechatAuthenticationToken
     * @param authorities
     */
    public WechatAuthenticationToken(Object princpal,Collection<? extends GrantedAuthority> authorities) {
        super(authorities);
        this.principal = princpal;
        super.setAuthenticated(true);
    }

    @Override
    public Object getCredentials() {
        return null;
    }

    @Override
    public Object getPrincipal() {
        return this.principal;
    }
}
